package com.roc.web.action.agentReport;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.roc.page.BaseAction;
import com.roc.pojo.Operators;
import com.roc.service.transReport.IreportFormService;
import com.roc.util.constant.Constant;

/**    
*文件名称：              ReportFormAction.java  
*说明： 
*
*@createTime 2017年8月15日 上午10:12:29  
*@author     zbl  
*@version    1.0 
**/
@Controller
@Namespace("/reportForm")
public class ReportFormAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private final Logger  logger= Logger.getLogger(ReportFormAction.class);
	
	private String minDate; //最小日期
	private String maxDate; //最大日期
	
	@Autowired
	private IreportFormService reportService; //报表业务层
	/**
	 * 初始化页面
	 * */
	@Action(value = "init", results = { @Result(name = SUCCESS, location = "/pages/agent/agentTransStatistics.jsp"),
			@Result(name =ERROR, location = "/error.jsp") })
	public String initJsp() {
		setModuleCode("0");//初始化为0
		return SUCCESS;
	}
	
	/**
	 * 折线图
	 * */
	@Action(value = "line", results = { @Result(name = SUCCESS, location = "/pages/agent/agentTransStatistics.jsp"),
			@Result(name =ERROR, location = "/error.jsp") })
	public String handleLineChart(){
		Operators oper=(Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		try {
			List<Map<String, Object>> resultList=reportService.queryOperStatisticsById(String.valueOf(oper.getId()), minDate, maxDate);
			String resultStr=JSON.toJSONString(resultList);
			getRequest().setAttribute("resultList", resultStr);
			setModuleCode("1");//折线图
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			addActionError(e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}
	
	 
	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}
	
	 
}
